// pseudocode
/*

begin

	numeric nDay, nMonth, nYear, nFlag

	repeat
		accept nYear
	until nYear <= 1980 OR nYear >= 2013

	repeat
		accept nMonth

	until nMonth < 1 OR nMonth > 12

        nFlag = 1
	repeat
		accept nDay
		switch nMonth
		begin
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				if nDay < 1 OR nDay > 31
					nFlag = 0
				break
			case 4:
			case 6:
			case 9:
			case 11:
				if nDay < 1 OR nDay > 30
					nFlag = 0
				break
			case 2:
				if nYear % 400 ==0 OR (nYear % 4 == 0 AND NOT(nYear % 100 == 0))
                                begin
					if nDay < 1 OR nDay > 29
						nFlag = 0
                                end
				else
					if nDay < 1 OR nDay > 28
						nFlag = 0
			        break
                end

	until nFlag == 0

	display nDay, nMonth, nYear
	
end

*/


#include<stdio.h>
#include<conio.h>

void main()
{
	int nDay, nMonth, nYear;
        char cAns;

   do
   {	
	do
	{
        	clrscr();
		printf("Enter Year(from 1980 to 2013):");
                scanf("%d", &nYear);
	} while (nYear < 1980 || nYear > 2013);


	do
	{
        	printf("\nEnter month(from 1 to 12): ");
                scanf("%d", &nMonth);
	} while (nMonth < 1 || nMonth > 12);

	

	int nFlag;	
	do
        {
		//nFlag = 1;
		//accept nDay
		printf("\nEnter day: ");
                scanf("%d", &nDay);
		
               	nFlag = 1;

		switch (nMonth)
		{//begin
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				if (nDay < 1 || nDay > 31)
                                        {
						nFlag = 0;
	                                        printf("Please enter a valid day from 1 to 31");
					}			
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				if (nDay < 1 || nDay > 30)
                                        {
						nFlag = 0;
						printf("Please enter a valid day from 1 to 30");
                                        }
				break;
			case 2:
				if (nYear % 400 == 0 || (nYear % 4 == 0 && nYear % 100 != 0))
                                {//begin
					if (nDay < 1 || nDay > 29)
                                                {
							nFlag = 0;
                                                        printf("Please enter valid day from 1 to 29");
                                                }
                                                //break;
                                }//end
				else
					if (nDay < 1 || nDay > 28)
                                                {
							nFlag = 0;
							printf("Please enter valid day from 1 to 28");
                                                }
			        break;
		}//end switch
                

         } while (nFlag == 0);
	//until nFlag == 0

	printf("\nThe date is: %d/%d/%d",nDay,nMonth, nYear);

	printf("\nContinue..?(Y/N)");
	cAns = getch();
        printf("%c", cAns);

   } while (cAns == 'y' || cAns == 'Y');
}